import java.util.Stack;

/**
 * @author Sebastian
 * @version 2.0
 * @date 2024/7/4 20:53
 */
// 最小栈 单栈解法
    //https://leetcode.cn/problems/min-stack/description/
public class MinStack2 {
    Stack<Integer> stk = new Stack<Integer>();

    public MinStack2(Stack<Integer> stk) {
        this.stk = stk;
    }

    public void push(int x) {
        if (stk.isEmpty()) {
            stk.push(x);
            stk.push(x);
        } else {
            int temp = stk.peek();
            stk.push(x);
            if (temp < x) {
                stk.push(temp);
            } else {
                stk.push(x);
            }
        }
    }

    public void pop() {
        stk.pop();
        stk.pop();
    }

    public int top() {
        return stk.get(stk.size() - 2);
    }

    public int getMin() {
        return stk.peek();
    }
}
